package net.wanho.controller;

import lombok.RequiredArgsConstructor;
import net.wanho.entity.User;
import net.wanho.service.UserService;
import net.wanho.vo.AjaxResult;
import org.springframework.web.bind.annotation.*;

/**
 * Author：汤小洋
 * Date：2023-10-08 9:09
 * Description：<描述>
 */
@RestController
@RequestMapping("/user")
@RequiredArgsConstructor
public class UserController {

    private final UserService userService;

    @GetMapping("/{id}")
    public AjaxResult findById(@PathVariable Integer id){
        User user = userService.findById(id);
        return AjaxResult.success(user);
    }

    @PutMapping
    public AjaxResult modify(@RequestBody User user){
        userService.modify(user);
        return  AjaxResult.success();
    }

    @DeleteMapping("/{id}")
    public AjaxResult removeById(@PathVariable Integer id){
        userService.removeById(id);
        return AjaxResult.success();
    }

    @DeleteMapping("/all")
    public AjaxResult removeAll(){
        userService.removeAll();
        return AjaxResult.success();
    }
}
